<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Muse","version":"7.7.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="title: python有关 date：2020-4-6 终端退出python命令行的方法两种方法  在”&gt;&gt;&gt;” 命令行状态输入 quit()并按回车 在 “&gt;&gt;&gt;”命令行状态输入 ctrl+Z 并按回车  python中的import语句Python中的import语句是用来调用（导入）模块的。 模块其实就是一些函数和类的集合文件，它能实现一些相应的功能，">
<meta property="og:type" content="article">
<meta property="og:title" content="python有关">
<meta property="og:url" content="http://yoursite.com/2020/04/06/python%E6%9C%89%E5%85%B3/index.html">
<meta property="og:site_name" content="tender healer">
<meta property="og:description" content="title: python有关 date：2020-4-6 终端退出python命令行的方法两种方法  在”&gt;&gt;&gt;” 命令行状态输入 quit()并按回车 在 “&gt;&gt;&gt;”命令行状态输入 ctrl+Z 并按回车  python中的import语句Python中的import语句是用来调用（导入）模块的。 模块其实就是一些函数和类的集合文件，它能实现一些相应的功能，">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://yoursite.com/2020/04/06/python%E6%9C%89%E5%85%B3/image-20200411213825350.png">
<meta property="article:published_time" content="2020-04-06T14:49:15.087Z">
<meta property="article:modified_time" content="2020-04-16T15:06:14.900Z">
<meta property="article:author" content="YQ Cong">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://yoursite.com/2020/04/06/python%E6%9C%89%E5%85%B3/image-20200411213825350.png">

<link rel="canonical" href="http://yoursite.com/2020/04/06/python%E6%9C%89%E5%85%B3/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>python有关 | tender healer</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">tender healer</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">Recording learning gains</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/04/06/python%E6%9C%89%E5%85%B3/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="YQ Cong">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="tender healer">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          python有关
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-04-06 22:49:15" itemprop="dateCreated datePublished" datetime="2020-04-06T22:49:15+08:00">2020-04-06</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-04-16 23:06:14" itemprop="dateModified" datetime="2020-04-16T23:06:14+08:00">2020-04-16</time>
              </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>title: python有关</p>
<p>date：2020-4-6</p>
<h1 id="终端退出python命令行的方法"><a href="#终端退出python命令行的方法" class="headerlink" title="终端退出python命令行的方法"></a>终端退出python命令行的方法</h1><p>两种方法</p>
<ol>
<li>在”&gt;&gt;&gt;” 命令行状态输入 quit()并按回车</li>
<li>在 “&gt;&gt;&gt;”命令行状态输入 ctrl+Z 并按回车</li>
</ol>
<h1 id="python中的import语句"><a href="#python中的import语句" class="headerlink" title="python中的import语句"></a>python中的import语句</h1><p>Python中的import语句是用来调用（导入）模块的。</p>
<p>模块其实就是一些函数和类的集合文件，它能实现一些相应的功能，当我内们需要使用这些功能的时容候，直接把相应的模块导入到我们的程序中，我们就可以使用了。</p>
<p>通常模块为一个文件，直接使用import来导入就好了。可以作为module的文件类型有”.py”、”.pyo”、”.pyc”、”.pyd”、”.so”、”.dll”。</p>
<h1 id="import-sys模块"><a href="#import-sys模块" class="headerlink" title="import sys模块"></a>import sys模块</h1><p>首先，利用import语句 输入 sys模块。（即<strong>import sys</strong>）基本上，这句语句告诉Python，我们想要使用这个模块。sys模块包含了与Python解释器和它的环境有关的函数。</p>
<p>当Python执行import  sys语句的时候，它在sys.path变量中所列目录中寻找sys.py模块。如果找到了这个文件，这个模块的主块中的语句将被运行，然后这个模块将能够被你 使用 。注意，初始化过程仅在我们 第一次 输入模块的时候进行。另外，“sys”是“system”的缩写。</p>
<p>Sys模块函数之多，以下为其中几个：</p>
<h2 id="1-sys-argv"><a href="#1-sys-argv" class="headerlink" title="(1)sys.argv"></a>(1)sys.argv</h2><p>这个可以实现给程序在外部传递参数。如： Test.py</p>
<p>Import sys<br> Print sys.argv[number]</p>
<p>一般情况下，number为0是这个脚本的名字，1，2…则为命令行下传递的参数.如：<br> Test.py脚本内容：<br> import sys</p>
<p> print sys.argv[0]<br> print sys.argv[1]<br> print sys.argv[2]<br> print sys.argv[3]<br> 那么<br> [root@databak scripts]# python text.py arg1 arg2 arg3<br> test.py<br> arg1<br> arg2<br> arg3<br> 看到，对应的关系了吗？<br> sys模块中的argv变量通过使用点号指明——sys.argv——这种方法的一个优势是这个名称不会与任何在你的程序中使用的argv变量冲突。另外，它也清晰地表明了这个名称是sys模块的一部分。</p>
<p>sys.argv变量是一个字符串的列表。特别地，sys.argv包含了 命令行参数 的列表，即使用命令行传递给你的程序的参数。</p>
<p>这里，当我们执行python using_sys.py we are arguments的时候，我们使用python命令运行using_sys.py模块，后面跟着的内容被作为参数传递给程序。Python为我们把它存储在sys.argv变量中。</p>
<p>记住，<strong>脚本的名称总是sys.argv列表的第一个参数</strong>。所以，在这里，’using_sys.py’是sys.argv[0]、’we’是sys.argv[1]、’are’是sys.argv[2]以及’arguments’是sys.argv[3]。注意，Python从0开始计数，而非从1开始。</p>
<h2 id="2-sys-platform"><a href="#2-sys-platform" class="headerlink" title="(2)sys.platform"></a>(2)sys.platform</h2><p> 大家都知道，当今的程序比较流行的是跨平台。简单的说就是这段程序既可以在windows下，换到linux下也可以不加修改的运行起来，听起来就不错。所以，这个函数就可以派上用场了。<br> 假设，我们想实现一个清除终端，linux下用clear, windows下用cls<br> ostype=sys.platform()<br> If ostype==”linux” or ostype==”linux2”:<br> Cmd=”clear”<br> Else:<br>  Cmd=”cls”</p>
<h2 id="3-sys-exit-n"><a href="#3-sys-exit-n" class="headerlink" title="(3) sys.exit(n)"></a>(3) sys.exit(n)</h2><p> 执行至主程序的末尾时,解释器会自动退出. 但是如果需要中途退出程序, 你可以调用sys.exit 函数, 它带有一个可选的整数参数返回给调用它的程序. 这意味着你可以在主程序中捕获对sys.exit 的调用。（注：0是正常退出，其他为不正常，可抛异常事件供捕获!）<br> sys.exit从python程序中退出，将会产生一个systemExit异常，可以为此做些清除除理的工作。这个可选参数默认正常退出状态是0，以数值为参数的范围为：0-127。其他的数值为非正常退出，还有另一种类型，在这里展现的是strings对象类型。</p>
<h2 id="4-sys-path"><a href="#4-sys-path" class="headerlink" title="(4)sys.path"></a>(4)sys.path</h2><p> 在使用模块的某一个功能前，是不是需要导入呢？答案是需要。那import,<strong>import</strong>命令就不用提干嘛的了吧。那在执行import module_name的时候，python内部发生了什么呢？简单的说，就是搜索module_name。根据sys.path的路径来搜索module_name</p>
<p>sys.path包含输入模块的目录名列表。我们可以观察到sys.path的第一个字符串是空的——这个空的字符串表示当前目录也是sys.path的一部分，这与PYTHONPATH环境变量是相同的。这意味着你可以直接输入位于当前目录的模块。否则，你得把你的模块放在sys.path所列的目录之一。</p>
<h2 id="5-sys-modules"><a href="#5-sys-modules" class="headerlink" title="(5)sys.modules"></a>(5)sys.modules</h2><h2 id="6-sys-stdin-sys-stdout-sys-stderr"><a href="#6-sys-stdin-sys-stdout-sys-stderr" class="headerlink" title="(6)sys.stdin,sys.stdout,sys.stderr"></a>(6)sys.stdin,sys.stdout,sys.stderr</h2><p> stdin , stdout , 以及stderr 变量包含与标准I/O 流对应的流对象. 如果需要更好地控制输出,而print 不能满足你的要求, 它们就是你所需要的. 你也可以替换它们, 这时候你就可以重定向输出和输入到其它设备( device ), 或者以非标准的方式处理它们</p>
<h1 id="import-binascii模块"><a href="#import-binascii模块" class="headerlink" title="import binascii模块"></a>import binascii模块</h1><p>binascii用来进行进制和字符串之间的转换</p>
<p>用法，例1：</p>
<p>import binascii<br>s = ‘abcde’<br>h = binascii.b2a_hex(s)    # 字符串转16进制  ‘6162636465’<br>h = binascii.hexlify(s)    # 作用同上</p>
<p>s = binascii.a2b_hex(h)    # 16进制转字符串  ‘abcde’<br>s = binascii.unhexlify(h)  # 作用同上</p>
<p>hex(512)      # 10进制转16进制 ‘0x200’<br>int(0x200)     # 16进制转10进制 512<br>int(‘200’, 16)   # 作用同上<br>int(‘1111’, 2)   # 2进制转10进制  15</p>
<p>例 2：</p>
<p>import binascii as B<br>s = ‘abcde’<br>h = B.b2a_hex(s)    # 字符串转16进制  ‘6162636465’<br>h = B.hexlify(s)    # 作用同上</p>
<p>s = B.a2b_hex(h)    # 16进制转字符串  ‘abcde’<br>s = B.unhexlify(h)  # 作用同上</p>
<p>hex(512)            # 10进制转16进制  ‘0x200’<br>int(0x200)          # 16进制转10进制  512<br>int(‘200’, 16)      # 作用同上<br>int(‘1111’, 2)      # 2进制转10进制   15</p>
<h1 id="import-string模块"><a href="#import-string模块" class="headerlink" title="import string模块"></a>import string模块</h1><figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&gt;&gt;</span>&gt; import string</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a=<span class="string">"asfds eea sdf"</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.capitalize()<span class="comment">#将字符串的首字母大写</span></span><br><span class="line"><span class="string">'Asfds eea sdf'</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.count(<span class="string">"a"</span>)<span class="comment">#a字母在字符串中出现的次数</span></span><br><span class="line"><span class="number">2</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.center(<span class="number">50</span>)<span class="comment">#将原字符串用空格填充成一个长度为width的字符串，原字符串内容居中</span></span><br><span class="line"><span class="string">'                  asfds eea sdf                   '</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.decode(encoding=<span class="string">"utf-8"</span>,errors=<span class="string">"strict"</span>)<span class="comment">#以指定编码格式解码字符串</span></span><br><span class="line">u<span class="string">'asfds eea sdf'</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.encode(encoding=<span class="string">"utf-8"</span>,errors=<span class="string">"strict"</span>)<span class="comment">#以指定编码格式编码字符串</span></span><br><span class="line"><span class="string">'asfds eea sdf'</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.endswith(<span class="string">"f"</span>)<span class="comment">#判断字符串是否以字符串f结尾</span></span><br><span class="line">True</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.find(<span class="string">"e"</span>)<span class="comment">#返回字符串e在字符串中的位置索引，没有则返回-1</span></span><br><span class="line"><span class="number">6</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.index(<span class="string">"f"</span>)<span class="comment">#和find方法一样</span></span><br><span class="line"><span class="number">2</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.isalnum()<span class="comment">#如果str至少有一个字符并且都是字母或数字则返回true，否则返回false</span></span><br><span class="line">False</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.isalpha()<span class="comment">#如果str至少有一个字符并且都是字母则返回true，否则返回false</span></span><br><span class="line">False</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.isdigit()<span class="comment">#如果str只包含数字则返回true，否则返回false</span></span><br><span class="line">False</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.islower()<span class="comment">#如果str中的字符都是小写则返回true</span></span><br><span class="line">True</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.isspace()<span class="comment">#如果str只包含空格，则返回true，否则返回false</span></span><br><span class="line">False</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.istitle()<span class="comment">#如果str是标题化的(单词首字母大写)则返回true，否则返回false</span></span><br><span class="line">False</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.isupper()<span class="comment">#如果str中的字符都是大写则返回true</span></span><br><span class="line">False</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.ljust(<span class="number">20</span>)<span class="comment">#返回一个原字符串左对齐的并使用空格填充至长度width的新字符串</span></span><br><span class="line"><span class="string">'asfds eea sdf       '</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.partition(<span class="string">"f"</span>)<span class="comment">#用"f"将str切分成三个值</span></span><br><span class="line">(<span class="string">'as'</span>, <span class="string">'f'</span>, <span class="string">'ds eea sdf'</span>)</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.partition(<span class="string">"h"</span>)<span class="comment">#用"h"将str切分成三个值，但是原字符串中没有h，所以后面加上两''</span></span><br><span class="line">(<span class="string">'asfds eea sdf'</span>, <span class="string">''</span>, <span class="string">''</span>)</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.replace(<span class="string">"s"</span>,<span class="string">"k"</span>)<span class="comment">#将字符串中的s替换成k</span></span><br><span class="line"><span class="string">'akfdk eea kdf'</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.rfind(<span class="string">"e"</span>)<span class="comment">#类似于find()函数，不过是从右边开始查找</span></span><br><span class="line"><span class="number">7</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.rindex(<span class="string">"e"</span>)<span class="comment">#类似于index()函数，不过是从右边开始</span></span><br><span class="line"><span class="number">7</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.rjust(<span class="number">20</span>)<span class="comment">#返回一个原字符串右对齐的并使用空格填充至长度width的新字符串</span></span><br><span class="line"><span class="string">'       asfds eea sdf'</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.rpartition(<span class="string">"s"</span>)<span class="comment">#类似于partition()函数，不过是从右边开始查找</span></span><br><span class="line">(<span class="string">'asfds eea '</span>, <span class="string">'s'</span>, <span class="string">'df'</span>)</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.rpartition(<span class="string">"k"</span>)</span><br><span class="line">(<span class="string">''</span>, <span class="string">''</span>, <span class="string">'asfds eea sdf'</span>)</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.split(<span class="string">"a"</span>)<span class="comment">#以a为分割符切到str</span></span><br><span class="line">[<span class="string">''</span>, <span class="string">'sfds ee'</span>, <span class="string">' sdf'</span>]</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a=<span class="string">"sfsdadf\ngagdasga\ngg"</span></span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.splitlines()<span class="comment">#按照行分割，返回一个包含各行作为元素的列表</span></span><br><span class="line">[<span class="string">'sfsdadf'</span>, <span class="string">'gagdasga'</span>, <span class="string">'gg'</span>]</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.startswith(<span class="string">"sf"</span>)<span class="comment">#检查字符串是否是以sf开头的，是的话返回true，否则返回false</span></span><br><span class="line">True</span><br><span class="line"><span class="meta">&gt;&gt;</span>&gt; a.zfill(<span class="number">30</span>)<span class="comment">#返回长度为30的字符串，原字符串右对齐，前面填充0</span></span><br><span class="line"><span class="string">'00000000000sfsdadf\ngagdasga\ngg'</span></span><br></pre></td></tr></table></figure>



<p>import string</p>
<p>string.ascii_letters  大小写字母<br>‘abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’<br>string.ascii_lowercase  小写字母<br>‘abcdefghijklmnopqrstuvwxyz’<br>string.ascii_uppercase  大写字母<br>‘ABCDEFGHIJKLMNOPQRSTUVWXYZ’<br>string.digits  数字<br>‘0123456789’<br>set(string.digits) 集合<br>{‘0’, ‘7’, ‘3’, ‘9’, ‘2’, ‘1’, ‘8’, ‘4’, ‘6’, ‘5’}<br>string.hexdigits  16进制<br>‘0123456789abcdefABCDEF’<br>string.octdigits  8进制<br>‘01234567’<br>string.punctuation 符号<br>‘!”#$%&amp;&#39;()<em>+,-./:;&lt;=&gt;?@[\]^_`{|}~’<br>string.printable<br>‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!”#$%&amp;&#39;()</em>+,-./:;&lt;=&gt;?@[\]^_`{|}~ \t\n\r\x0b\x0c’<br>string.whitespace 空白符<br>‘ \t\n\r\x0b\x0c’</p>
<h1 id="str（）函数"><a href="#str（）函数" class="headerlink" title="str（）函数"></a>str（）函数</h1><p>str函数是Python的内置函数，它将参数转换成字符串类型，即人适合阅读的形式。</p>
<p>如，此脚本书写时用到了这个函数</p>
<p><img src="/2020/04/06/python%E6%9C%89%E5%85%B3/image-20200411213825350.png" alt="image-20200411213825350"></p>
<h1 id="os-getcwd-函数的用法"><a href="#os-getcwd-函数的用法" class="headerlink" title="os.getcwd()函数的用法"></a>os.getcwd()函数的用法</h1><p>获得当前路径</p>
<p>在Python中可以使用os.getcwd()函数获得当前的路径。</p>
<p>其原型如下所示：os.getcwd()</p>
<p>该函数不需要传递参数，它返回当前的目录。需要说明的是，当前目录并不是指脚本所在的目录，而是所运行脚本的目录。</p>
<p>&gt;&gt;&gt;import os</p>
<p>&gt;&gt;&gt;print os.getcwd()</p>
<p>D:\Program Files\Python27 </p>
<p>这里的目录即是python的安装目录。若把上面的两行语句保存为getcwd.py，保存于E:\python\盘，运行后显示是E:\python</p>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/04/05/%E7%AC%94%E8%AE%B0%E6%95%B4%E7%90%86%EF%BC%88%E6%97%A0%E5%88%86%E7%B1%BB%EF%BC%89/" rel="prev" title="笔记整理（无分类）">
      <i class="fa fa-chevron-left"></i> 笔记整理（无分类）
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/04/07/%E5%8E%8B%E7%BC%A9%E5%8C%85%E9%9A%90%E5%86%99/" rel="next" title="压缩包隐写">
      压缩包隐写 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#终端退出python命令行的方法"><span class="nav-number">1.</span> <span class="nav-text">终端退出python命令行的方法</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#python中的import语句"><span class="nav-number">2.</span> <span class="nav-text">python中的import语句</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#import-sys模块"><span class="nav-number">3.</span> <span class="nav-text">import sys模块</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-sys-argv"><span class="nav-number">3.1.</span> <span class="nav-text">(1)sys.argv</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-sys-platform"><span class="nav-number">3.2.</span> <span class="nav-text">(2)sys.platform</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-sys-exit-n"><span class="nav-number">3.3.</span> <span class="nav-text">(3) sys.exit(n)</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-sys-path"><span class="nav-number">3.4.</span> <span class="nav-text">(4)sys.path</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-sys-modules"><span class="nav-number">3.5.</span> <span class="nav-text">(5)sys.modules</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-sys-stdin-sys-stdout-sys-stderr"><span class="nav-number">3.6.</span> <span class="nav-text">(6)sys.stdin,sys.stdout,sys.stderr</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#import-binascii模块"><span class="nav-number">4.</span> <span class="nav-text">import binascii模块</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#import-string模块"><span class="nav-number">5.</span> <span class="nav-text">import string模块</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#str（）函数"><span class="nav-number">6.</span> <span class="nav-text">str（）函数</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#os-getcwd-函数的用法"><span class="nav-number">7.</span> <span class="nav-text">os.getcwd()函数的用法</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">YQ Cong</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">13</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">YQ Cong</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v4.2.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://muse.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Muse</a> v7.7.1
  </div>

        








      </div>
    </footer>
  </div>

  
  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="/lib/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
